var app = getApp(),
  $ = require("../../utils/httpHelper.js")
Page({
  data: {
    // tab切换  
    currentTab: 0,
    objarr: [],
    page: 1,
    pagesize: 10,
    totalpage: 0,//最大页数,
    height:0,
    showDialog: false,
    expTextName: '物流信息',
    wlist: []
  },
  onLoad: function (option) {
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        console.log(res);
        that.setData({ height: res.windowHeight - 40 })
      }
    })
    this.getData(0)
  },
  
  getData(index){
    let params = {
      rd_session: app.globalData.userInfo.rd_session,
      page: this.data.page,
      pagesize: this.data.pagesize,
      trade_status : index,
    }
    $.httpPost('order_jifen_list', params, (data, err) => {
      this.setData({
        objarr: data.data.list,
        totalpage: data.total_page,
        currentTab: index,
      })
    })
  },
  clicktab(e){
    console.log(e.currentTarget.dataset.tab)
    let tab = e.target.dataset.tab
    if (this.data.currentTab != tab){
      this.setData({
        currentTab: tab,
        page: 1,
      })
      this.getData(tab)
    }
  },
  shouh(e){
    let orderno = e.currentTarget.dataset.orderno
    let params = {
      rd_session: app.globalData.userInfo.rd_session,
      order_no: orderno
    }
    $.httpPost('receive_jifen_order', params, (data, err) => {
      if(data.result == 'success'){
        this.setData({
          currentTab: 2,
          page: 1,
        })
        this.getData(2)
      }
    })
  },

  wlinfo(e) {
    let types = e.currentTarget.dataset.type
    let no = e.currentTarget.dataset.no
    let orderno = e.currentTarget.dataset.orderno
    let par = {
      rd_session: app.globalData.userInfo.rd_session,
      order_no: orderno,
      express_type: types,
      express_no: no
    }
    $.httpPost('express_info', par, (data, err) => {
      console.log(data.data.data)
      if (data.result == 'success') {
        this.setData({
          wlist: data.data.data,
          expTextName: data.data.expTextName,
          showDialog: true
        })
      }
      console.log(this.data.wlist[0].time)
    })

  },

  closewl() {
    this.setData({
      showDialog: false
    })
  },
  //滑动到底部 上拉加载
  scrollBottom: function () {
    this.data.page++
    console.log(this.data.page)
    console.log(this.data.totalpage)
    if (this.data.page > this.data.totalpage) {
      this.setData({
        nomore: false
      })
    } else {
      let params = {
        rd_session: app.globalData.userInfo.rd_session,
        page: this.data.page,
        pagesize: this.data.pagesize,
        trade_status: this.data.currentTab
      }
      $.httpPost('order_jifen_list', params, (data, err) => {
        let arr = this.data.objarr;
        for (let item of data.data.list) {
          arr.push(item);
        }
        this.setData({
          objarr: arr
        })
      })


    }

  },
  
    
})  